package com.yc.forum.servlet;

import com.yc.forum.dao.RedisDao;
import com.yc.forum.util.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

//判断当前用户是否点赞，是返回1，没有返回-1
@WebServlet(name = "UserBooleanSuppServert",value = "/UserBooleanSuppServert.s")
public class UserBooleanSuppServert extends HttpServlet {
    RedisDao redisDao =new RedisDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session= req.getSession();
        String account;
        try{
            account=session.getAttribute("loginedUser").toString();
            String replyid=req.getParameter("replyid");
            List<String> listaccount=redisDao.queryReplySuppAccount(replyid);
            int a= listaccount.lastIndexOf(account);
            System.out.println("a="+a);
            Utils.toJson(a,resp);
        }catch(Exception e){
            Utils.toJson(-1,resp);
        }
    }
}
